package com.commerce.reader.ui.dashboard;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.commerce.reader.Entity.Books;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class DashboardViewModel extends ViewModel {

    private MutableLiveData<List<Books>> mBooks;

    public DashboardViewModel() {
        mBooks = new MutableLiveData<>();
        List<Books> all = LitePal.findAll(Books.class);
        mBooks.setValue(all);
    }

    public LiveData<List<Books>> getBooks() {
        return mBooks;
    }
    public void fBooks(String s) {
        List<Books> listBooks = new ArrayList<>();
        for (Books books:LitePal.findAll(Books.class)) {
           if(books.getName().contains(s)){
               listBooks.add(books);
           }
        }
        mBooks.setValue(listBooks);
    }
}